package com.cubeofnine.sugar.service.element;

import java.util.Hashtable;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;

public class Address implements KvmSerializable {

	private String address_type;
	private String street;
	private String city;
	private String state;
	private String postalcode;
	private String country;

	public Address() {
		super();
	}

	public Address(String address_type, String street, String city,
			String state, String postalcode, String country) {
		super();
		this.address_type = address_type;
		this.street = street;
		this.city = city;
		this.state = state;
		this.postalcode = postalcode;
		this.country = country;
	}

	public Address(SoapObject obj) {
		super();
		try {
			this.address_type = obj.getProperty("address_type").toString();
		} catch (Exception e) {
			this.address_type = null;
		}

		try {
			this.street = obj.getProperty("street").toString();
		} catch (Exception e) {
			this.street = null;
		}

		try {
			this.city = obj.getProperty("city").toString();
		} catch (Exception e) {
			this.city = null;
		}

		try {
			this.state = obj.getProperty("state").toString();
		} catch (Exception e) {
			this.state = null;
		}

		try {
			this.postalcode = obj.getProperty("postalcode").toString();
		} catch (Exception e) {
			this.postalcode = null;
		}

		try {
			this.country = obj.getProperty("country").toString();
		} catch (Exception e) {
			this.country = null;
		}
	}

	public Object getProperty(int index) {
		Object object = null;

		switch (index) {
		case 0:
			object = this.address_type;
			break;
		case 1:
			object = this.street;
			break;
		case 2:
			object = this.city;
			break;
		case 3:
			object = this.state;
			break;
		case 4:
			object = this.postalcode;
			break;
		case 5:
			object = this.country;
			break;
		}

		return object;
	}

	public int getPropertyCount() {
		return 6;// Count GloVariable
	}

	public void getPropertyInfo(int index, Hashtable arg1,
			PropertyInfo propertyInfo) {
		switch (index) {
		case 0:
			propertyInfo.name = "address_type";
			propertyInfo.type = PropertyInfo.STRING_CLASS;
			break;
		case 1:
			propertyInfo.name = "street";
			propertyInfo.type = PropertyInfo.STRING_CLASS;
			break;
		case 2:
			propertyInfo.name = "city";
			propertyInfo.type = PropertyInfo.STRING_CLASS;
			break;
		case 3:
			propertyInfo.name = "state";
			propertyInfo.type = PropertyInfo.STRING_CLASS;
			break;
		case 4:
			propertyInfo.name = "postalcode";
			propertyInfo.type = PropertyInfo.STRING_CLASS;
			break;
		case 5:
			propertyInfo.name = "country";
			propertyInfo.type = PropertyInfo.STRING_CLASS;
			break;
		}
	}

	public void setProperty(int index, Object obj) {
		switch (index) {
		case 0:
			this.address_type = obj.toString();
			break;
		case 1:
			this.street = obj.toString();
			break;
		case 2:
			this.city = obj.toString();
			break;
		case 3:
			this.state = obj.toString();
			break;
		case 4:
			this.postalcode = obj.toString();
			break;
		case 5:
			this.country = obj.toString();
			break;
		}
	}

	public String getAddress_type() {
		return address_type;
	}

	public void setAddress_type(String address_type) {
		this.address_type = address_type;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getPostalcode() {
		return postalcode;
	}

	public void setPostalcode(String postalcode) {
		this.postalcode = postalcode;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	@Override
	public String toString() {
		return "Address [address_type=" + address_type + ", street=" + street
				+ ", city=" + city + ", state=" + state + ", postalcode="
				+ postalcode + ", country=" + country + "]";
	}

}
